<template>
  <a-modal :title="title" :width="width" :visible="visible" @ok="handleOk" :okButtonProps="{ class: { 'jee-hidden': disableSubmit } }" @cancel="handleCancel" cancelText="关闭">
    <LabItemsRecordDeviceForm ref="registerForm" :recordId="recordId" @ok="submitCallback" :formDisabled="disableSubmit" :formBpm="false"></LabItemsRecordDeviceForm>
  </a-modal>
</template>

<script lang="ts" setup>
  import { ref, nextTick, defineExpose,watch } from 'vue';
  import LabItemsRecordDeviceForm from './LabItemsRecordDeviceUsageRateForm.vue'
  
  const title = ref<string>('');
  const width = ref<number>(1200);
  const visible = ref<boolean>(false);
  const disableSubmit = ref<boolean>(false);
  const registerForm = ref();
  const emit = defineEmits(['register', 'success']);

  let recordId = ref("");
  
  /**
   * 编辑 
   * @param record
   */
  function edit(record) {
    recordId.value = record.id;
    title.value = '运行记录';
    visible.value = true;
  }
  //监听itemID变化
  watch(recordId, (newValue, oldValue) => {
    nextTick(() => {
      registerForm.value.reloadTable(newValue);
    });
  });

  
  /**
   * 确定按钮点击事件
   */
  function handleOk() {
    registerForm.value.submitForm();
  }

  /**
   * form保存回调事件
   */
  function submitCallback() {
    handleCancel();
    emit('success');
  }

  /**
   * 取消按钮回调事件
   */
  function handleCancel() {
    visible.value = false;
  }

  defineExpose({
    edit,
    disableSubmit,
  });
</script>

<style>
  /**隐藏样式-modal确定按钮 */
  .jee-hidden {
    display: none !important;
  }
</style>
